#ifndef __MESSAGE_H__
#define __MESSAGE_H__

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <sys/types.h>
#include <sys/socket.h>

/*
 * number of bits reserved for the flag of the Message
 *****************************************************/
#define FLAG_SIZE 8

/*
 * Number of bits reserved for data to be sent
 *****************************************************/
#define DATA_SIZE 120
#define PACK_SIZE FLAG_SIZE + DATA_SIZE;

/*
 * The Message class is used to pass information back
 * and forth between two connections
 *****************************************************/
class Message {
	
	public:
		// Basic constructor
		Message( void );

		// Set flag and data
		Message( const char* flag, char* data );
		
		// Send Message over socket
		bool release( int sock );

		// Receive a Message via socket
		int  receive( int sock );
		
		// Returns data of Message.
		char* getData( void ) const;

		// Return flag of Message.
		char* getFlag( void ) const;

		// Return size in bytes
		int getBytes( void ) const;

		// Return socket of Message.
		int getSocket( void ) const;

		// Return the length of data in the Message
		int getDataLength( void ) const;

		// Return the length of the flag of the Message.
		int getFlagLength( void ) const;
		
	private:
		// Character String holding Message data.
		char data[DATA_SIZE];

		// Character string holding flag of Message.
		char flag[FLAG_SIZE];

		// Holds the length of data from Message
		uint_t dataLength;

		// Number of bytes in Message
		uint_t bytes;

		// Socket
		uint_t socket;
		
		// Set Message flag
		void setFlag( const char* flag, uint_t size );

		// Set Message data
		void setData( char* data, uint_t size );

		// set Message data length call this to seer the length of the Message
		uint_t setDataLength( void );

		// Calculate and set data bytes. Call this to calculate the bytes of the Message
		uint_t setBytes( void );

		// Explicitly set the bytes of the Message
		uint_t setBytes( uint_t );
};

#endif